<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/pages/jsp/common/head.jsp"%>
<%
currentTab	= "listOrder";
%>
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/js/extendArray.js" ></script>
<div class="wrapnme">
<!--citeLeft-->
    <%@ include file="/pages/jsp/common/left.jsp"%>
    <!--citeLeft结束-->    
    <!--sideRight-->
    <div class="sideRight">
		<!--title-->
        <div class="Right_title">
        	贷款信息添加
        </div>
        <!--title结束-->        
        <!--content-->
        <div class="content">
        	<div style="color:red;">
        		<c:forEach var="error" items="${errors}" varStatus="count">
        			<div>${count.index + 1}.${error}</div>
        		</c:forEach>
        	</div>
        	<form action="${pageContext.request.contextPath}/daikuan.do?action=addDaikuanSave" method="post">
	        	 <table width="100%" border="1" class="tablesorter" >
	        		<!--<tr>
	        			<th>所在省份</th>
	        			<td><select id="province" name="province">
	        				<option>请选择</option>
	        			<%
	        				java.util.Map<String,java.util.List<com.daikuan.vo.CitiesVO>> citiesMap	= com.daikuan.util.Global.citiesMap;
	        				for(java.util.Map.Entry<String,java.util.List<com.daikuan.vo.CitiesVO>> entry : citiesMap.entrySet()){
	        					%>
	        						<option value="<%=entry.getKey()%>"><%=entry.getKey()%></option>
	        					<%
	        				}
	        			%></select></td>
	        			<th>所在城市</th>
	        			<td><div id="citiesDIV"></div></td>	        			
	        		</tr>
	        		 -->
	        		<tr>
	        			<th><a href="${pageContext.request.contextPath}/pages/jsp/ajax/addArea.jsp" rel="facebox" >添加发布城市</a></th>	        			
	        			<td id="citiesTD"></td>
	        			<th>机构类型:</th>
	        			<td>
		        			<c:forEach var="company" items="${companyVOList}">
		        				<input type="radio" id="companyID" name="companyID" ${daikuanVO.companyID == company.id ? "checked='checked'" : ""} id="companyType${company.id}" value="${company.id}" />${company.name}
		        			</c:forEach>
	        			</td>		        			
	        		</tr>
	        		<tr>	        		
	        			<th>机构名称:</th>
	        			<td><input name="organization" type="text" value="${daikuanVO.organization}" /></td>
	        			<th>产品图片:</th>
	        			<td><input type="file" name="image" value="${daikuanVO.image}" /></td>
	        		</tr>
	        		<tr>	        			
	        			<th>产品名称:</th>
	        			<td><input name="name" type="text" value="${daikuanVO.name}" /></td>
	        			<th>产品类型:</th>
	        			<td><c:forEach var="daikuanTypeVO" items="${daikuanTypeVOList}">
	        				<input type="radio" name="daikuanTypeID" id="daikuanTypeID" ${daikuanTypeVO.id == daikuanVO.daikuanTypeID ? "checked='checked'" : "" } daikuanType${daikuanTypeVO.id}" value="${daikuanTypeVO.id}" />${daikuanTypeVO.name}
	        			</c:forEach></td>
	        		</tr>
	        		<tr>
	        			<th>产品简单描述:</th>
	        			<td><textarea name="summary">${daikuanVO.summary}</textarea></td>
	        			<th>产品描述</th>
	        			<td><textarea name="description">${daikuanVO.description}</textarea></td>
	        		</tr>	        		
	        		<tr>
	        			<th>产品要求简单说明:</th>
	        			<td><textarea name="requirementsDescription">${daikuanVO.requirementsDescription}</textarea></td>
	        			<th>利率描述</th>
	        			<td><textarea name="rateDescription">${daikuanVO.rateDescription}</textarea></td>
	        		</tr>
	        		<tr>
	        			<th>贷款最低额(万元):</th>
	        			<td><input name="minAmount" type="text" value="${not empty daikuanVO.minAmount ? daikuanVO.minAmount : '0.0' }" /></td>
	        			<th>贷款最高额(万元):</th>
	        			<td><input name="maxAmount" type="text" value="${not empty daikuanVO.maxAmount ? daikuanVO.maxAmount : '0.0' }" /></td>
	        		</tr>
	        		<tr>
	        			<th>贷款最短时间(月):</th>
	        			<td><input name="minBorrowingTime" type="text" value="${daikuanVO.minBorrowingTime}" /></td>
	        			<th>贷款最长时间(月):</th>
	        			<td><input name="maxBorrowingTime" type="text" value="${daikuanVO.maxBorrowingTime}" /></td>
	        		</tr>
	        		<tr>
	        			<th>最低利率(%):</th>
	        			<td><input name="minInterestRate" type="text" value="${not empty daikuanVO.minInterestRate ? daikuanVO.minInterestRate : '0.0' }" /></td>
	        			<th>最高利率(%):</th>
	        			<td><input name="maxInterestRate" type="text" value="${not empty daikuanVO.maxInterestRate ? daikuanVO.maxInterestRate : '0.0' }" /></td>
	        		</tr>
	        		<tr>
	        			<th>审核时间(天):</th>
	        			<td><input name="loansTime" type="text" value="${daikuanVO.loansTime}" /></td>
	        			<th>申请条件:</th>
	        			<td><textarea name="conditionsApply">${daikuanVO.conditionsApply}</textarea></td>
	        		</tr>
	        		<tr>
	        			<th>所需材料:</th>
	        			<td><textarea name="materialsNeeded">${daikuanVO.materialsNeeded}</textarea></td>
	        			<th>还款类型:</th>
	        			<td><%
	        				Object daikuanVOObj					= request.getAttribute("daikuanVO");
	        				java.util.List<String> repaymentTypes	= new java.util.ArrayList<String>(); 
	        				if(null != daikuanVOObj){
	        					com.daikuan.vo.DaikuanVO daikuanVO	= (com.daikuan.vo.DaikuanVO)daikuanVOObj;
	        					String repayments					= common.util.StringUtil.isEmptyRetString(daikuanVO.getRepayments());
	        					if(null != repayments){
	        						String[] retypes				= repayments.split(",");
	        						for(String retype : retypes){
	        							repaymentTypes.add(retype);
	        						}
	        					}
	        				}
		        			Object repaymentVOListObj	= request.getAttribute("repaymentVOList");
		        			if(null != repaymentVOListObj){
		        				java.util.List<com.daikuan.vo.RepaymentVO> list	= (java.util.List<com.daikuan.vo.RepaymentVO>)repaymentVOListObj;
		        				for(com.daikuan.vo.RepaymentVO vo : list){
		        					Long id		= vo.getId();
		        					String name	= vo.getName();	
	        						
	        			%>
	        				<input type="checkbox" name="repaymentTypes" <%=repaymentTypes.contains(id.toString()) ? "checked='checked'" : "" %> id="repayment<%=id%>" value="<%=id%>" /><%=name%>
	        			<%}}%>
	        			</td>
	        		</tr>
	        		<tr>
	        			<th>薪金要求:</th>
	        			<td><input type="text" name="wage" id="wage" value="${daikuanVO.wage}" />元</td>
	        			<th>薪金是否需要打卡</th>
	        			<td>
		        			<input type="checkbox" name="wagePunch" id="wagePunch" value="1" ${daikuanVO.wagePunch == 1 ? "checked='checked'" : ""} />
	        			</td>
	        		<tr>
	        		<tr>
	        			<th>目前在职工作时间:</th>
	        			<td><input type="text" name="workTime" id="workTime" value="${empty daikuanVO.workTime ? '0' :daikuanVO.workTime}" />月</td>
	        			<th>申请最小年龄</th>
	        			<td>
		        			<input type="text" name="minAge" id="minAge" value="${empty daikuanVO.minAge ? '0' : daikuanVO.minAge}" />岁
	        			</td>
	        		<tr>
	        		<tr>
	        			<th>要求经营时间:</th>
	        			<td><input type="text" name="operateTime" id="operateTime" value="${empty daikuanVO.operateTime ? '0' : daikuanVO.operateTime}" />月</td>
	        			<th>申请最大年龄</th>
	        			<td>
		        			<input type="text" name="maxAge" id="maxAge" value="${empty daikuanVO.maxAge ? '150' : daikuanVO.maxAge}" />岁
	        			</td>
	        		<tr>
	        		<tr>
	        			<th>要求家庭收入(企业贷款):</th>
	        			<td><input type="text" name="householdIncome" id="householdIncome" value="${empty daikuanVO.householdIncome ? '0' : daikuanVO.householdIncome}" />元</td>
	        			<th>其它申请条件</th>
	        			<td>
		        			<table width="100%" border="1" class="tablesorter" >		        					        					
			        				<%
			        				java.util.Map<String,java.util.List<com.daikuan.vo.DaikuanConditionVO>> map	= com.daikuan.util.Global.mapConditions;
			        				java.util.Set<String> keys	= map.keySet();
			        				for(String key : keys){
			        					String parentName	= "";
			        					java.util.List<com.daikuan.vo.DaikuanConditionVO> listVO	= map.get(key);
			        					if(null != listVO && listVO.size() > 0){
			        						parentName	= listVO.get(0).getParentName();
			        					
			        					%>
			        					<tr>
			        					<td>
			        						<%=parentName%>
			        					</td>
				        					<td>
				        						<%
				        							for(com.daikuan.vo.DaikuanConditionVO vo : listVO){
				        								Long id			= vo.getId();
				        								String name		= vo.getName();
				        								%>
				        									<%=name%><input type="checkbox" id="conditionTypes" name="conditionTypes" value="<%=key%>_<%=id%>" />
				        								<%
				        							}
				        						%>
				        					</td>
			        					</tr>
			        					<%
			        					}
			        				}
			        				%>
		        			</table>
	        			</td>
	        		<tr>
	        		<tr>
	        			<td colspan="4" style="text-align:center;"><input type="submit" value="提交" class="submit" /></td>        			
	        		</tr>
	        	</table>
        	</form>
        <!-- content结束-->
 	</div>
    <!--sideRight结束-->
</div>
<!--wrap结束-->
<script type="text/javascript">
	var AREA_DATA	= new Array();
	function fillImage(){
		$('#faceboxContent').html('<img src="${pageContext.request.contextPath}/scripts/js/jquery/facebox/loading.gif" alt="loading" />');
	}
	function getCitiesArea(){
		var $val	= $('#areaProvince').val();
		$('#areaCityTD').html('');
		var optionStr	= '<input type="checkbox" id="allCities" onclick="citiesAllChoose();" value="1" />全选<br/>';
		<%
		for(java.util.Map.Entry<String,java.util.List<com.daikuan.vo.CitiesVO>> entry : citiesMap.entrySet()){
			String province		= entry.getKey();
			%>
				if($val == '<%=province%>'){
					optionStr+="<%
						java.util.List<com.daikuan.vo.CitiesVO> list	= entry.getValue();
						for(com.daikuan.vo.CitiesVO vo : list){
							String cityName	= vo.getCityName();
							Long id			= vo.getId();
							out.print("<div><input type='checkbox' name='leftCityIDs' id='leftCityIDs' value='"+id+"' data-name='"+cityName+"'/>"+cityName+"<br/></div>");
						}
					%>";
				}
			<%
		}
		%>
		$('#areaCityTD').append(optionStr);
	}
	function citiesAllChoose(){
		var $checked	= $("#allCities").attr("checked");
		if($checked){
			$('input[name="leftCityIDs"]').attr("checked",true);
		}else{
			$('input[name="leftCityIDs"]').attr("checked",false);
		}
	}
	function moveAreaCity(){
		var $leftCitiesArray	= $('input[name="leftCityIDs"]:checked');
		var $newStr				= '';
		$('#sureAreaCity').html('');
		for(var i=0;i<$leftCitiesArray.size();i++){
			var $obj	= $leftCitiesArray[i];
			var $objVal	= $($obj).val();
			var $name	= $($obj).attr('data-name');
			
			//if(!AREA_DATA.hasOwnProperty($objVal)){
				AREA_DATA[$objVal] = $name;
			//}
		}
		for(var $key in AREA_DATA){
			if(AREA_DATA.hasOwnProperty($key)){
				var $val	= AREA_DATA[$key];
				$newStr += '<input type="checkbox" checked="checked" name="cityIDs" id="cityIDs" value="'+$key+'" />'+$val+'<br/>';
			}
		}
		$newStr	= '<input type="checkbox" value="allCountry" id="allCountry" onclick="checkAllCountry();" value="-1" />全国<br/>'+$newStr;
		$('#sureAreaCity').append($newStr);
	}
	function checkAllCountry(){
		var $checked	= $("#allCountry").attr("checked");
		if($checked){
			$('input[name="cityIDs"]').attr("disabled",true);
		}else{
			$('input[name="cityIDs"]').attr("disabled",false);
		}
	}
	function saveAreaCity(){
		faceboxClose();
		var $checked	= $("#allCountry").attr("checked");
		var $tdStr		= '';
		if($checked){
			$tdStr		= '<input type="checkbox" checked="checked" value="allCountry" id="allCountry" value="-1" />全国';
		}else{
			for(var $key in AREA_DATA){
				if(AREA_DATA.hasOwnProperty($key)){
					var $val	= AREA_DATA[$key];
					$tdStr += '<input type="checkbox" checked="checked" name="cityIDs" id="cityIDs" value="'+$key+'" />'+$val+'<br/>';
				}
			}
		}
		$('#citiesTD').html($tdStr);
	}
	$(document).ready(function(){
		facebox($('a[rel*=facebox]'));
	});
</script>
<%@ include file="/pages/jsp/common/footer.jsp"%>